<template>
  <!-- 计算公式维护 -->
  <base-breadcrumb :title="$route.meta.title">
    <searchData :searchData="searchArr" @search="search"></searchData>

    <a-card :bordered="false">
      <div class="table-operator">
      <a-button v-btnPermission="[{code:'seex_pm_047_add_02',ident:'prma_seex'},{code:'buco_pm_047_add_02',ident:'prma_buco'}]" type="primary" :loading="isAdd" icon="plus" @click="handleManage(2, {})">新增</a-button>
      </div>
      <!-- 表格 -->
      <list-table
        ref="table"
        :page-keys="['pageNo', 'pageSize']"
        tableLayout="fixed"
        size="default"
        rowKey="id"
        :columns="columns"
        :request="loadData"
        :alert="true"
        show-size-changer
        show-quick-jumper
        showPagination="auto"
      >
        <template slot="action" slot-scope="text, record">
          <MoreButton>
            <a v-btnPermission="[{code:'seex_pm_047_loo_01',ident:'prma_seex'},{code:'buco_pm_047_loo_01',ident:'prma_buco'}]" @click="handleManage(0, record)">查看</a>
            <!-- 编辑 -->
            <span v-if="((record.auditStatus == 'DRAFT' || record.auditStatus == 'REJECTED') && record.creatorId == $userInfo().id)&&hideBuquBtn()">
              <a @click="handleManage(1, record)">编辑</a>
            </span>
            <!-- 删除 -->
            <span v-if="((record.auditStatus == 'DRAFT' || record.auditStatus == 'REJECTED') && record.creatorId == $userInfo().id)&&hideBuquBtn()">
              <a @click="handleRemoveParams({ id: record.id })">删除</a>
            </span>
            <span v-if="record.auditStatus === 'PAST' || record.auditStatus === 'SUBMITTED' || record.auditStatus === 'REJECTED' || record.auditStatus === 'ABOLISH'">
              <approval-button :status="record.auditStatus" :id="record.id"></approval-button>
            </span>
          </MoreButton>
        </template>
        <template slot="auditStatus" slot-scope="text, record">
          <list-status :status="record.auditStatus" :isApproval="true" conversion="en" :text="text"></list-status>
        </template>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>

<script>
import { STable } from '@/components' // 表格
import BasePage from '@/views/basePage' // 基础配置
import { api } from '@/api/project/performanceAnalysis'
import MoreButton from '@/components/MoreButton'
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import { typeListApproval1 } from '@/utils/util'
const columns = [
  {
    title: '序号',
    width: 80,
    dataIndex: 'index',
    customRender() {
      return arguments[2] + 1
    }
  },
  {
    title: '分公司',
    width: 100,
    dataIndex: 'branchCompanyName'
  },
  {
    title: '项目名称',
    width: 100,
    dataIndex: 'projectName'
  },
  {
    title: '是否重点项目',
    width: 100,
    dataIndex: 'keyProgram',
  },
  {
    title: '月份',
    width: 100,
    dataIndex: 'month'
  },
  {
    title: '不考核指标',
    dataIndex: 'nochekIndex',
    width: 120
  },
  {
    title: '状态',
    dataIndex: 'auditStatus',
    width: 140,
    scopedSlots: { customRender: 'auditStatus' }
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: 200,
    scopedSlots: { customRender: 'action' }
  }
]
const searchArr = [
  {
    name: '所属单位',
    valueKey: 'searchQuery',
    type: OrgTreeSelect,
  },
  // {
  //   name: '所属分公司',
  //   valueKey: 'branchCompanyId',
  //   type: SelectSubCompany
  // },
  // {
  //   name: '所属项目',
  //   keyValue: 'branchCompanyId',
  //   valueKey: 'projectId',
  //   type: SelectProject
  // },
  {
    name: '月份',
    type: 'month',
    value: 'month',
    attrs: {
      valueFormat: 'YYYY-MM'
    }
  },

  {
    name: '状态',
    value: 'auditStatus',
    type: 'select',
    data: typeListApproval1
  }
]
export default {
  name: 'a' + Date.now(),
  extends: new BasePage(),
  components: {
    STable,
    MoreButton
  },
  data() {
    this.columns = columns
    this.searchArr = searchArr
    return {
      queryParam: {}, // 查询参数
      isAdd: false,

      removeApi: { remove: api.delNoAssessment },
      loadData: async (parameter) => {
        const requestParameters = Object.assign({}, parameter, { query: this.queryParam })

        return api.listNoAssessment(requestParameters).then((res) => {
          return res
        })
      }
    }
  },
  methods: {
    //搜索
    search(value) {
      value && (this.queryParam = value)
      this.$refs.table.refresh(true)
    },
    // 操作栏
    async handleManage(type, record) {
      if (type == 2) {
        this.isAdd = true
        const res = await api.getIsAddNoAssessment({ projectId: this.$userInfo().currentPost.deptId })
        this.isAdd = false
        if (!res.data) {
          this.$warning({
            title: '提示',
            content: '您所在项目部不需填写项目部履约分析，或履约分析已提交，不能进行不考核申请。'
          })
          return
        }
      }

      let query = {
        editModel: type
      }
      if (record && record.id) {
        query.id = record.id
      }
      this.$router.push({
        name: 'updateNoAssessment',
        query
      })
    }
  }
}
</script>
